//
//  SettingSandTableLampView.m
//  YIJU2.0-HD
//
//  Created by 陈柏兵 on 16/5/9.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "SettingSandTableLampView.h"
#import "UILabel+TitleAndDetail.h"
#import "UILabel+ColorAndText.h"
#import "Masonry.h"
#import "Macro.h"

@interface SettingSandTableLampView()
@property (nonatomic, strong) NSArray *titleArray;//title数组
@property (nonatomic, strong) NSArray *dataArray;//数据数组
@property (nonatomic, strong) UILabel *lampNameLabel;
@end

@implementation SettingSandTableLampView
- (SettingSandTableLampView *)initWithDetailArray:(NSArray *)detailArray {
    if (self == [super init]) {
        _dataArray = [NSArray array];
        _dataArray = detailArray;
        [self drawLampUI];
    }
    return self;
}

- (void)drawLampUI {
    _lampNameLabel = [[UILabel alloc] init];
    _lampNameLabel.backgroundColor = [UIColor randomColor];
    _lampNameLabel.font = TextFont17;
    _lampNameLabel.textColor = [UIColor whiteColor];
    _lampNameLabel.textAlignment = NSTextAlignmentCenter;
    _lampNameLabel.layer.cornerRadius = 6.0f;
    _lampNameLabel.layer.masksToBounds = YES;
    [self addSubview:_lampNameLabel];
    [_lampNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.width.equalTo(self.mas_width);
        make.height.equalTo(self.mas_height).multipliedBy(1/3.0f);
    }];
    
    UILabel *lastLabel = nil;
    for (int i = 0; i < 3; i ++) {
        UILabel *titleLabel = [UILabel labelWithTextFont:11 TextColor:[UIColor lightGrayColor] titleText:self.titleArray[i] detailText:self.dataArray[i]];
        
        [self addSubview:titleLabel];
        if (lastLabel == nil) {
            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.lampNameLabel.mas_bottom).offset(TenOffsetViewMargin);
                make.left.equalTo(self.mas_left);
                make.width.equalTo(self.mas_width);
                make.height.equalTo(self.mas_height).multipliedBy(2/12.0f);
            }];
        }else {
            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(lastLabel.mas_bottom);
                make.left.equalTo(self.mas_left);
                make.width.equalTo(self.mas_width);
                make.height.equalTo(self.mas_height).multipliedBy(2/12.0f);
            }];
        }
        lastLabel = titleLabel;
    }
}

- (NSArray *)titleArray {
    if (_titleArray == nil) {
        _titleArray = @[@"Ip:",@"port:",@"cmd:"];
    }
    return _titleArray;
}

- (void)setTitleString:(NSString *)titleString {
    _titleString = titleString;
    self.lampNameLabel.text = titleString;
    
    
}



@end
